package com.itsu.shirojwt.response;

import org.springframework.http.HttpStatus;

import lombok.Getter;

@Getter
public class ResObj<T> {

    private int status;
    private String message;
    private T data;

    private ResObj(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    private ResObj(int status, String message) {
        this(status, message, null);
    }

    private ResObj(int status, T data) {
        this(status, null, data);
    }

    private ResObj(int status) {
        this(status, null, null);
    }

    private ResObj() {
    }

    public static ResObj create() {
        return new ResObj<>();
    }

    public ResObj withStatus(int status) {
        this.status = status;
        return this;
    }

    public ResObj withMessage(String message) {
        this.message = message;
        return this;
    }

    public ResObj withData(T data) {
        this.data = data;
        return this;
    }

    public static ResObj ok() {
        return new ResObj<>(HttpStatus.OK.value());
    }

    public static ResObj ok(String message) {
        return new ResObj<>(HttpStatus.OK.value(), message);
    }

    public static <T> ResObj ok(T data) {
        return new ResObj<>(HttpStatus.OK.value(), data);
    }

    public static <T> ResObj ok(String message, T data) {
        return new ResObj<>(HttpStatus.OK.value(), message, data);
    }

    public static ResObj error() {
        return new ResObj<>(HttpStatus.INTERNAL_SERVER_ERROR.value());
    }

    public static ResObj error(String message) {
        return new ResObj<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), message);
    }

    public static ResObj noAuthen() {
        return new ResObj<>(HttpStatus.UNAUTHORIZED.value());
    }

    public static ResObj noAuthen(String message) {
        return new ResObj<>(HttpStatus.UNAUTHORIZED.value(), message);
    }
}